package com.sinosoft.cpyy;

import com.sinosoft.cpyy.config.systeminit.StartupInitialize;
import com.sinosoft.cpyy.util.spring.SpringContextUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;

/**
 * @author nicai
 */
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
@EnableCircuitBreaker
@Slf4j
public class Application {
    public static void main(String[] args) {
        ConfigurableApplicationContext run = SpringApplication.run(Application.class, args);
        // 注入上下文
        SpringContextUtil.setApplicationContext(run);
        // 初始化项目任务
        StartupInitialize startupInitialize = SpringContextUtil.getBean("startupInitialize", StartupInitialize.class);
        if (startupInitialize == null) {
            log.error("项目启动失败，初始化任务未完成");
        } else {
            startupInitialize.init(run);
            log.info("初始化任务执行完成");
        }
    }
}